#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <GL/glew.h>
#include <gl/GLU.h>
#include <GLFW/glfw3.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include "cCUIWidget.h"
#include "cCUIBrush.h"
#include "cCUIImage.h"


using namespace std;

#define CUI_NoParent NULL

//Callback identifiers.
#define CUI_OnLoad 0001

struct sCUIEvent
{
};

typedef void (*CUICallBack)(sCUIEvent);
class cCUIWindow;

struct sCUIWindowDetails {
	GLFWwindow *windowHandle;
	cCUIWindow *parentWindow;
	vector<cCUIWindow*> children;
	vector<cCUIWidget*> widgets;
	char title[255];
	int width, height;
	bool visible;
};

struct sCUIRGB {
	float r, g, b;
};

sCUIRGB CUIRGB(float r, float g, float b);

class cCUIWindow
{
public:
	cCUIWindow(cCUIWindow *parent, const char *title, int width, int height);
	~cCUIWindow();

	void show(bool showSetting);
	void pollEvents();
	GLFWwindow* getWindow();
	void addChild(cCUIWindow *child);
	void addWidget(cCUIWidget *widget);
	void addCallBack(CUICallBack callback, int id);
	void update();
	void setBackground(cCUIImage* background);

	bool running;
	bool firstrun;
	sCUIRGB backgroundColor;

private:
	bool bgImage;
	void paint();
	void drawWidgets();
	cCUIImage *backgroundImage;
	sCUIWindowDetails windowDetails;
	CUICallBack callbacks[255];
	cCUIBrush *brush;
};